/**
 * 
 */
package com.hy.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author yoka24443
 *
 */
@WebServlet(name = "CheckLogin", urlPatterns = "/CheckLogin")
public class CheckLoginServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		HttpSession session = req.getSession();
		resp.setContentType("text/html;charset=utf-8");
		String userName = req.getParameter("userName");
		String password = req.getParameter("password");
		
		if(userName.equals("yoka24443") && password.equals("123456")) {
			session.setAttribute("userName", userName);
			req.getRequestDispatcher("success.jsp").forward(req, resp);
		} else {
			req.getRequestDispatcher("fail.jsp").forward(req, resp);
		}
	}

}
